<template>
    <div class="products-list">
        <ul class="list-unstyled clearfix">
            <li v-for="(item,index) in productList" :key="index">
                <div class="item">
                    <div class="product-thumb">
                        <router-link :to="'/product/view/'+jumpUrl(item.product_name)" :title="item.product_name" class="product-url">
                            <img class="img-responsive" :src="item.image_path" :alt="item.product_name" />
                        </router-link>
                    </div>
                    <div class="product-area">
                        <div class="product-name">
                            <router-link :to="'/product/view/'+jumpUrl(item.product_name)" :title="item.product_name" class="product-url">
                                <h5 v-text="item.product_name"></h5>
                            </router-link>
                        </div>
                        <div class="price-box">
                            <span class="special-price">{{item.special_price | Currency}}</span>
                            <span class="old-price">{{item.old_price | Currency}}</span>
                        </div>
                        <div class="product-color">
                            <div v-if="item.colorList.length <= 1" class="swatch selected">
                                <div class="swatch-color" :style="{borderColor:item.colorList[0].color}"></div>
                            </div>
                            <div v-else v-for="(colors,i) in item.colorList" :key="i" class="swatch" :class="{'selected':item.color_current==i}" @mouseenter="setProduct({ parentIndex:index, childIndex: i, productName:colors.product_name, productImage:colors.image_path, productPrice:colors.price })">
                                <div class="swatch-color" :style="{borderColor:colors.color}"></div>
                            </div>
                        </div>
                    </div>
                </div>
            </li>
        </ul>
    </div>
</template>
<script>
import mixin from '../../mixin'
export default {
    mixins: [mixin],
    props: ['productList'],
    methods: {
        setProduct(data) { // 鼠标经过色块，切换对应商品信息
            let parentIndex = data.parentIndex
            let childIndex = data.childIndex
            let productName = data.productName
            let productImage = data.productImage
            let productPrice = data.productPrice
            let ele = this.productList[parentIndex]

            ele.product_name = productName
            ele.image_path = productImage
            ele.special_price = productPrice.special
            ele.old_price = productPrice.oldprice
            ele.color_current = childIndex
        }
    }
}
</script>
<style scoped>
.products-list li {
    float: left;
    position: relative;
    margin: 1%;
    overflow: hidden;
}

.products-list .item {
    padding-bottom: 60px;
    border-bottom: 2px solid #efefef;
    -webkit-transition: all .3s;
    transition: all .3s;
}

.products-list .item:hover {
    border-bottom-color: #000;
}

.product-name {
    position: relative;
    height: 45px;
    overflow: hidden;
}

.product-name h5 {
    position: absolute;
    left: 0;
    bottom: 0;
    margin-top: 0;
    margin-bottom: 5px;
    max-height: 33px;
    font-size: 12px;
    color: #1f1f1f;
    text-transform: uppercase;
    line-height: 1.43;
}

.products-list .special-price {
    font-weight: bold;
}

.products-list .old-price {
    padding-left: 5px;
    color: #aaa;
    text-decoration: line-through;
    font-size: 12px;
}

.bottom-toolbar .sort-by {
    display: none;
}

.product-color {
    padding-top: 3px;
}

.product-color .swatch {
    float: left;
    display: inline-block;
    width: 20px;
    height: 20px;
    margin: 3px 3px 3px 0;
    overflow: hidden;
    border: 1px solid #e0e0e0;
    -webkit-transition: all .3s;
    transition: all .3s;
}

.product-color .swatch.selected {
    border-color: #000;
}

.product-color .swatch-color {
    width: 0;
    height: 0;
    padding: 0;
    border-width: 9px;
    border-style: solid;
    cursor: pointer;
}

.product-color .selected .swatch-color {
    margin: 1px;
    border-width: 8px;
}

@media (max-width: 767px) {
    .products-list ul {
        margin: 0 -2%;
    }
    .products-list li {
        width: 46%;
        margin: 0 2%;
    }
}

@media (min-width: 768px) {
    .products-list ul {
        margin: 0 -1%;
    }
    .products-list li {
        margin: 1%;
    }
}

@media (min-width: 768px) and (max-width: 991px) {
    .products-list li {
        width: 31.333%;
    }
}

@media (min-width: 992px) and (max-width: 1599px) {
    .products-list li {
        width: 23%;
    }
}

@media (min-width: 1600px) and (max-width: 1899px) {
    .products-list li {
        width: 18%;
    }
}

@media (min-width: 1900px) {
    .products-list li {
        width: 14.66666667%;
    }
}
</style>